package com.example.demo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.example.demo.mapper.MyAccessTokenMapper;
import com.example.demo.model.MyAccessToken;
import com.example.demo.service.MyAccessTokenService;

@Service("myAccessTokenService")
public class MyAccessTokenServiceImpl extends BaseServiceImpl<MyAccessToken> implements MyAccessTokenService {

	@Autowired
	private MyAccessTokenMapper myAccessTokenMapper;

	@Override
	public List<MyAccessToken> findAll() {
		return myAccessTokenMapper.findAll();
	}

	@Override
	public void insert(MyAccessToken entity) {
		myAccessTokenMapper.insert(entity);
	}

	@Override
	@Transactional
	public void create(MyAccessToken entity) {
		//删除旧token然后保存新token
		MyAccessToken queryAccessToken = new MyAccessToken();
		queryAccessToken.setUserAccount(entity.getUserAccount());
		myAccessTokenMapper.delete(queryAccessToken);
		myAccessTokenMapper.insert(entity);
	}
}
